<?php
// 对比系统管理和打卡积分菜单
$host = '127.0.0.1';
$port = 3306;
$database = 'qiandao';
$username = 'root';
$password = 'root';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 对比一级菜单 ===\n\n";
    
    $stmt = $pdo->query("SELECT * FROM system_menu WHERE pid = 0 ORDER BY sort DESC, id ASC");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($menus as $menu) {
        echo "菜单: {$menu['title']}\n";
        echo "  ID: {$menu['id']}\n";
        echo "  PID: {$menu['pid']}\n";
        echo "  Sort: {$menu['sort']}\n";
        echo "  Status: {$menu['status']}\n";
        echo "  URL: '{$menu['url']}'\n";
        echo "  Node: '{$menu['node']}'\n";
        echo "  Icon: '{$menu['icon']}'\n";
        echo "  Target: '{$menu['target']}'\n";
        echo "  Params: '{$menu['params']}'\n";
        echo "  Create_at: {$menu['create_at']}\n";
        
        // 统计子菜单数量
        $stmt2 = $pdo->prepare("SELECT COUNT(*) FROM system_menu WHERE pid = ? AND status = 1");
        $stmt2->execute([$menu['id']]);
        $subCount = $stmt2->fetchColumn();
        echo "  子菜单数量: {$subCount}\n";
        
        echo "\n";
    }
    
    echo "=== 检查打卡积分的子菜单 ===\n\n";
    
    $stmt = $pdo->query("SELECT id, pid, title, status, url, node FROM system_menu WHERE pid = 25 ORDER BY sort DESC, id ASC");
    $subs = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($subs)) {
        echo "✗ 打卡积分没有子菜单！\n";
    } else {
        foreach ($subs as $sub) {
            echo "  - {$sub['title']} (ID:{$sub['id']}, Status:{$sub['status']}, URL:'{$sub['url']}', Node:'{$sub['node']}')\n";
        }
    }
    
    echo "\n=== 建议 ===\n\n";
    echo "如果打卡积分菜单有子菜单但还是不显示，可能的原因：\n";
    echo "1. 菜单缓存问题\n";
    echo "2. URL字段必须是'#'（一级菜单）\n";
    echo "3. 需要有至少一个启用的子菜单\n";
    echo "4. 权限过滤问题\n";
    
} catch (PDOException $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

